﻿@using Coralcode.Adapter.TextualAnalyzer.Entity.Domains
@using Coralcode.Base.Entity
@using Coralcode.Base.Utils
@using CoralNode.Core.Entity.Domains.User
@using CoralNode.Core.Entity.Enums
@using CoralNode.MvcClient.Helper
@using CoralNode.Core.Entity.Domains.Prototype
@using CoralNode.MvcClient.Contexts
@model IList<PrototypeDomain>

@Html.IncludePage("CoralAdmin/sitesetting", "_Left", new { current = "search" })
<style>
    .checkbox_own { margin-top: 6px; }
</style>
@{
    long[] prototypeIds = ViewBag.PrototypeIds;
}
<div id="pbody">
    <div class="extra">
        <div class="pbody_top">
            <span class="ico ico_setting_system"></span><span class="t t_c">网站设置&nbsp;&nbsp;/&nbsp;&nbsp;<b
                class=" t_small f_no">搜索设置</b></span>
        </div>
        <div id="main" class="userList_cnt">
            <div class="content_tab extra_normal">
                <div class="tablist extra_normal">
                    <a href="/m/sitesetting/sitesearchsetting" class="current">搜索设置</a>
                    <a href="/m/sitesetting/siteindexsetting">站点索引</a>
                </div>
                <a class="btn_5 f_r mr_1 mt_0-5 js_searchIndex" href="/m/sitesetting/SaveSiteIndexSetting">
                    添加索引</a>
            </div>
            <div class="pt_1 js_tabcnt ">
                <div>
                    <form action="/m/sitesetting/sitesearchsetting" method="post" enctype="multipart/form-data">
                        <div class="table_form form_main">
                            @if (@ViewBag.Msg != null) {
                                <div class="error_msg">
                                    @ViewBag.Msg.Msg
                                </div>
                            }
                            <table data-js="tabCnt">
                                <tbody>
                                    <tr>
                                        <th width="80"><span class="info_txt">原型：</span></th>
                                        <td>
                                            @foreach (var item in Model) {
                                                <span class="f_l mr_2">
                                                    <label class="mr_0-5 checkbox_own @(prototypeIds.Contains(item.Id) ? "selected" : string.Empty)">
                                                        <input  type="checkbox" class="mt_0-5" value="@item.Id" name="ids" @(prototypeIds.Contains(item.Id) ? "checked=checked" : string.Empty)/>
                                                    </label>
                                                    @item.Title
                                                </span>
                                            }
                                        </td>
                                    </tr>
                                    <tr>
                                        <th width="80"><span class="info_txt">索引：</span></th>
                                        <td>
                                            <input type="button" class="btn_2 btn js_updateindex" value="更新全部索引" />
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                        <div class="submitbox p_2 extra_normal">
                            <input type="submit" class="btn_1" value="提    交" />
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
<script>
    $(function () {
        $(".js_updateindex").click(function () {
            $.post("/m/sitesetting/RebuildIndex", function (data) {
                if (data.Type == 5) {
                    $.alert(data.Msg);
                } else {
                    $.alert(data.Msg, "error");
                }
            });
        });
        $(".js_tab").each(function () {
            var $this = $(this);
            $this.tabs($this.next().children());
        });
        $(".js_searchIndex").click(function (e) {
            e.preventDefault();
            var $this = $(this);
            var dialog = $.dialog({
                title: "站点索引",
                content: '<img src="/Themes/CoralAdmin/_misc/images/loading.gif" style="display:block; margin:30px auto;" />',
                show: true,
                cancel: true,
                lock: true,
                ok: okfun,
                zIndex: 999
            });
            dialog.getJQuery().find(".d-state-highlight").css("margin-left", "140px");
            function okfun() {
                var $form = dialog.getJQuery().find("form");
                $.post($form.attr("action"), $form.serialize(), function (result) {
                    if (result.Type == 5) {
                        $.alert(result.Msg);
                        setTimeout(function () {
                            dialog.close();
                            location.reload();
                        }, 2000);
                    } else {
                        $.alert(result.Msg, "error");
                    }
                });
            }
            var $this = $(this);
            dialog.visible();
            $.get($this.attr("href"), function (data) {
                dialog.content(data);
            });
        })
    })
</script>
